SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
GO

PRINT '---- tblMatches'

PRINT '-- Table title'

INSERT tblUFGTableTitles (utt_Tablename, utt_Languagename, utt_Title, utt_Description)
VALUES ('tblMatches','Nederlands','Wedstrijden','Wedstrijd gegevens')

PRINT '-- Column titles'

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_HomeClubName','Nederlands','Thuisclub','U dient een thuis spelende club in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_HomeSeason','Nederlands','Seizoen','U dient een seizoen in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_HomeTeamName','Nederlands','Thuisclub teamnaam','U dient een thuis spelende teamnaam in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_AgainstClubname','Nederlands','Tegenstander','U dient een tegenstander in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_AgainstSeason','Nederlands','Seizoen','U dient een seizoen in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_AgainstTeamName','Nederlands','Tegenstander teamnaam','U dient een tegenstander teamnaam in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_Date','Nederlands','Datum','U dient een datum in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_From','Nederlands','Begintijd','U dient een begintijd in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_To','Nederlands','Eindtijd','U dient een eindtijd in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_Clubname','Nederlands','Club voor locatie','U dient een club voor de locatie in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_ComplexName','Nederlands','Locatie','U dient een locatie in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_Field','Nederlands','Veld','U dient een veld in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_homegoals','Nederlands','Thuis Goals','U dient een Uitslag in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_againstgoals','Nederlands','uit Goals','U dient een uitslag in te vullen.')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblMatches','mat_Description','Nederlands','Omschrijving','U kunt hier een opschrijving in vullen.')

PRINT '-- Display'

UPDATE tblUFGTables 
SET utb_NrOfColumns = 1
WHERE utb_TableName = 'tblMatches' 

UPDATE tblUFGTables SET utb_DisplayInCategory = 'MAINTABLES' WHERE utb_TableName = 'tblComplex'

INSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblMatches',1,1,4,1)
iNSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblMatches',2,2,4,1)
iNSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblMatches',3,3,4,1)
iNSERT INTO dbo.tblUFGPanels (upn_TableName,upn_PanelNumber,upn_SequenceNumber,upn_NrOfColumns,upn_RowSpan)
VALUES ('tblMatches',4,4,4,1)


UPDATE tblUFGColumns 
SET ucl_PanelNumber = 1
WHERE ucl_TableName = 'tblMatches' 
AND ucl_ColumnName = 'mat_HomeClubname'
OR ucl_ColumnName = 'mat_HomeSeason'
OR ucl_ColumnName = 'mat_HomeTeamName'
OR ucl_ColumnName = 'mat_AgainstClubname'
OR ucl_ColumnName = 'mat_AgainstSeason'
OR ucl_ColumnName = 'mat_AgainstSeason'
OR ucl_ColumnName = 'mat_AgainstTeamName'
OR ucl_ColumnName = 'mat_Date'

UPDATE tblUFGColumns 
SET ucl_PanelNumber = 2
WHERE ucl_TableName = 'tblMatches' 
AND ucl_ColumnName = 'mat_Field'
OR ucl_ColumnName = 'mat_From'
OR ucl_ColumnName = 'mat_To'
OR ucl_ColumnName = 'mat_Clubname'
OR ucl_ColumnName = 'mat_ComplexName'


UPDATE tblUFGColumns 
SET ucl_PanelNumber = 3
WHERE ucl_TableName = 'tblMatches' 
AND ucl_ColumnName = 'mat_againstgoals'
OR ucl_ColumnName = 'mat_homegoals'


UPDATE tblUFGColumns 
SET ucl_PanelNumber = 4
WHERE ucl_TableName = 'tblMatches' 
AND ucl_ColumnName IN (
	'mat_Description'
)

-- Team van dezelfde club mag niet tegen zichzelf spelen
ALTER TABLE [dbo].[tblMatches]  WITH CHECK ADD  CONSTRAINT [Een team kan niet tegen zichzelf spelen.] CHECK  (NOT(([mat_HomeClubname]=[mat_AgainstClubname] AND [mat_HomeTeamName]=[mat_AgainstTeamName])))
GO

Print '-- RowRights'
INSERT tblUFGRowRights
	(urr_TableName,
	 urr_RoleName,
	 urr_SQLSelectExpression,
	 urr_SQLInsertExpression,
	 urr_SQLUpdateExpression,
	 urr_SQLDeleteExpression)
SELECT 'tblMatches',
	urr_Rolename,
	'dbo.fnGetClubnameByUser(@UFGUsername) IN (mat_Clubname)',
	'dbo.fnGetClubnameByUser(@UFGUsername) IN (mat_Clubname)',
	'dbo.fnGetClubnameByUser(@UFGUsername) IN (mat_Clubname)',
	'dbo.fnGetClubnameByUser(@UFGUsername) IN (mat_Clubname)'
FROM tblUFGRoles
WHERE urr_RoleName LIKE '%Club'